package com.fr.report.script.function;

import com.fr.base.FRContext;
import com.fr.data.TableData;
import com.fr.data.TableDataException;
import com.fr.data.core.DataUtils;
import com.fr.report.script.Calculator;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import java.util.logging.Level;
import java.util.logging.Logger;

public class COLCOUNT extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    String str = paramArrayOfObject[0].toString();
    Calculator localCalculator = getCalculator();
    TableData localTableData = DataUtils.getTableData4Function(localCalculator, str);
    try
    {
      return new Integer(localTableData.getColumnCount());
    }
    catch (TableDataException localTableDataException)
    {
      FRContext.getLogger().log(Level.WARNING, localTableDataException.getMessage(), localTableDataException);
    }
    return new Integer(0);
  }

  public Function.Type getType()
  {
    return Function.REPORT;
  }

  public String getCN()
  {
    return "COLCOUNT(tableData):返回tableData中列的个数。\ntableData:tableData的名字，字符串形式的。\n备注：\n    先从私有数据源中查找，然后再从公有数据源中查找，返回的是第一个查找到的tableData中列数。\n示例:\n以我们提供的数据源FRDemo为例\nCOLCOUNT(\"Check\")等于6。\nCOLCOUNT(\"country\")等于5。";
  }

  public String getEN()
  {
    return "";
  }
}